﻿using BaseDll;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Windows.Forms;

namespace OtherDevice
{
    [Description("COUSZ")]
    public class UV_COUSZ:UVControlBase
    {
        public UV_COUSZ(string strName) : base(strName)
        {
            controlFrom = new Form_UVControl();
        }
        public override double Function_Get光功率能量值(int n_Channal)
        {
            try
            {
                byte[] byteArray = new byte[8];
                byteArray[0] = 0x01;
                byteArray[1] = 0x03;
                byteArray[2] = (byte)(n_Channal & 0X00FF);
                byteArray[3] = 0x2C;
                byteArray[4] = 0x00;
                byteArray[5] = 0x02;
                int n_CRCValue = ParityType.CRC16(byteArray, 6);
                byteArray[6] = (byte)(n_CRCValue & 0X00FF);
                byteArray[7] = (byte)((n_CRCValue & 0XFF00) >> 8);
                byte[] S = null;
                if (SendAndReciveData(byteArray,ref S,500))
                {
                    return S[3] * 256 + S[4];
                }
                else
                {
                    return -999;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("UV光功率能量数据获取失败" + ex.Message);
                return -9999;
            }

        }
        public override double Function_Get电功率(int n_Channal)
        {
            try
            {
                byte[] byteArray = new byte[8];
                byteArray[0] = 0x01;
                byteArray[1] = 0x03;
                byteArray[2] = (byte)(n_Channal & 0X00FF);
                byteArray[3] = 0x27;
                byteArray[4] = 0x00;
                byteArray[5] = 0x02;
                int n_CRCValue = ParityType.CRC16(byteArray, 6);
                byteArray[6] = (byte)(n_CRCValue & 0X00FF);
                byteArray[7] = (byte)((n_CRCValue & 0XFF00) >> 8);
                byte[] S = null;
                if(SendAndReciveData(byteArray, ref S, 500))
                {
                    return S[3] * 256 + S[4];
                }
                else
                {
                    return -999;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("UV电功率数据获取失败" + ex.Message);
                return -9999;
            }

        }
        public override bool Function_Set电功率(int n_Channal, int n_Value)
        {
            try
            {
                byte[] byteArray = new byte[10];
                byteArray[0] = 0x01;
                byteArray[1] = 0x10;
                byteArray[2] = (byte)(n_Channal & 0X00FF);
                byteArray[3] = 0x26;
                byteArray[4] = 0x00;
                byteArray[5] = 0x02;
                byteArray[6] = (byte)(n_Value & 0X00FF);
                byteArray[7] = (byte)((n_Value & 0XFF00) >> 8);
                int n_CRCValue = ParityType.CRC16(byteArray, 8);
                byteArray[8] = (byte)(n_CRCValue & 0X00FF);
                byteArray[9] = (byte)((n_CRCValue & 0XFF00) >> 8);
                byte[] S = null;
                return SendAndReciveData(byteArray, ref S, 500);
            }
            catch (Exception)
            {
                return false;
            }
        }
        public override bool Function_监控电功率(int n_Channal)
        {
            try
            {
                byte[] byteArray = new byte[8];
                byteArray[0] = 0x01;
                byteArray[1] = 0x10;
                byteArray[2] = (byte)(n_Channal & 0X00FF);
                byteArray[3] = 0x25;
                byteArray[4] = 0x00;
                byteArray[5] = 0x02;
                int n_CRCValue = ParityType.CRC16(byteArray, 6);
                byteArray[6] = (byte)(n_CRCValue & 0X00FF);
                byteArray[7] = (byte)((n_CRCValue & 0XFF00) >> 8);
                byte[] S = null;
                return SendAndReciveData(byteArray, ref S, 500);
            }
            catch (Exception)
            {
                return false;
            }
        }

    }
}